package com.neuedu.yyzx.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.neuedu.yyzx.common.Ret;
import com.neuedu.yyzx.po.Customer;
import com.neuedu.yyzx.po.Customerpreference;
import com.neuedu.yyzx.service.CustomerpreferenceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author gao
 * 项目：yyzx-project
 * site:http://...
 * 描述：客户喜好 前端页面 preference 数据库 customerpreference
 * 思路：
 * @data 2025/4/10/13:39
 */
@RestController
@RequestMapping("/customerpreference")
public class CustomerPreferenceController {
    @Autowired
    private CustomerpreferenceService customerPreferenceService;

    // http://localhost:8080/customerpreference/selectWithCustomer
    // 客户喜好列表
    @GetMapping("/selectWithCustomer")
    public Ret<Page<Customerpreference>> selectWithCustomer(Page<Customerpreference> page, Customerpreference customerpreference) {  // 传的对象信息(看需要传输多少个数据 如果是多个用对象方便)
        return Ret.ok(customerPreferenceService.selectWithCustomer(page, customerpreference));
    }

    // 检查客户中未添加喜好的
    // http://localhost:8080/customerpreference/getCustomersWithoutPreference
    @GetMapping("/getCustomersWithoutPreference")
    public Ret<List<Customerpreference>> getCustomersWithoutPreference() {
        return Ret.ok(customerPreferenceService.getCustomersWithoutPreference());
    }

    // 保存或更新用户信息
    // http://localhost:8080/customerpreference/saveOrUpdate
    @PostMapping("/saveOrUpdate")
    // 前段的axios传递的json数据，需要使用@RequestBody注解
    public Ret<Boolean> saveOrUpdate(@RequestBody Customerpreference customerpreference) {
        boolean saveOrUpdate = customerPreferenceService.saveOrUpdate(customerpreference);
        return Ret.ok(saveOrUpdate);
    }

    // 根据主键查询 前段用于修改信息
    @GetMapping("/get/{id}")
    public Ret<Customerpreference> getById(@PathVariable int id) {
        Customerpreference customerpreference = customerPreferenceService.getById(id);
        return Ret.ok(customerpreference);
    }

    // 根据主键删除
    @DeleteMapping("/delete/{id}")
    public Ret<Boolean> removeById(@PathVariable int id) {
        return Ret.ok(customerPreferenceService.removeById(id));
    }





    // 没用上的
    // http://localhost:8080/customerpreference/selectCustomersWithoutPreference
    @GetMapping("/selectCustomersWithoutPreference")
    public Ret<Page<Customerpreference>> selectCustomersWithoutPreference(Page<Customerpreference> page, Customerpreference customerpreference) {  // 传的对象信息(看需要传输多少个数据 如果是多个用对象方便)
        return Ret.ok(customerPreferenceService.selectCustomersWithoutPreference(page, customerpreference));
    }
}
